package squareBorderPackage;

import static org.junit.Assert.*;

import java.math.BigDecimal;

import org.junit.*;

import temperaturePackage.*;

/**
 * A class collection tests for the class of doors.
 * 
 * @version	1.0
 * @author 	Jessa Bekker & Esther Alberts
 */
public class DoorTest {
	
	/**
	 * Instance variable referencing doors that may change during individual
	 * tests.
	 */
	private Door door;
	
	/**
	 * Instance variable referencing squares that may change during individual
	 * tests.
	 */
	private Square defaultSquare1, defaultSquare2;
	
	@Before
	public void setUp() {
		defaultSquare1 = new NormalSquare();
		defaultSquare2 = new NormalSquare(new Temperature(45, TemperatureUnit.CELSIUS),new BigDecimal(45));
		door = new Door(false, defaultSquare1, Direction.SOUTH);
		door.attachTo(defaultSquare2, Direction.NORTH);
		
	}
	
	
	@Test
	public void getSlippery_LegalCase() {
		assertFalse(door.getSlippery());
	}


	@Test
	public void isObstacle_True() {
		assertTrue(door.isObstacle());
	}
	
	@Test
	public void isObstacle_False() {
		door.setOpened(true);
		assertFalse(door.isObstacle());
	}
	
	@Test
	public void getStrongestBorder_DoorNull() {
		assertTrue(door.getStrongestBorder(null)
		instanceof Door);
	}

	@Test
	public void getStrongestBorder_DoorOpenBorder() {
		assertTrue(door.getStrongestBorder(new OpenBorder(defaultSquare1, Direction.WEST))
		instanceof Door);
	}
	
	@Test
	public void getStrongestBorder_DoorDoor() {
		assertTrue(door.getStrongestBorder(new Door(true, defaultSquare1, Direction.EAST))
		instanceof Door);
	}
	
	@Test
	public void getStrongestBorder_DoorWall() {
		assertTrue(door.getStrongestBorder(new Wall(true, defaultSquare1, Direction.FLOOR))
		instanceof Wall);
	}
	
	@Test
	public void split_Closed() {
		Door[] newDoors = door.split();
		assertTrue(newDoors[0].getSquareAt(Direction.SOUTH) == defaultSquare1);
		assertTrue(newDoors[0].getSquareAt(Direction.NORTH) == null);
		assertTrue(newDoors[1].getSquareAt(Direction.NORTH) == defaultSquare2);
		assertTrue(newDoors[1].getSquareAt(Direction.SOUTH) == null);
		assertFalse(newDoors[0].isOpened());
		assertFalse(newDoors[1].isOpened());
	}
	
	@Test
	public void split_Open() {
		door.setOpened(true);
		Door[] newDoors = door.split();
		assertTrue(newDoors[0].getSquareAt(Direction.SOUTH) == defaultSquare1);
		assertTrue(newDoors[0].getSquareAt(Direction.NORTH) == null);
		assertTrue(newDoors[1].getSquareAt(Direction.NORTH) == defaultSquare2);
		assertTrue(newDoors[1].getSquareAt(Direction.SOUTH) == null);
		assertTrue(newDoors[0].isOpened());
		assertTrue(newDoors[1].isOpened());
	}


	@Test
	public void setOpened_LegalCase() {
		door.setOpened(true);
		assertTrue(defaultSquare1.getSpace().equals(defaultSquare2.getSpace()));
		assertTrue(defaultSquare1.getTemperature().equals(defaultSquare2.getTemperature()));
		assertTrue(defaultSquare1.getTemperature().equals(new Temperature(35, TemperatureUnit.CELSIUS)));
		assertTrue(defaultSquare1.getHumidity().equals(defaultSquare2.getHumidity()));
		assertTrue(defaultSquare1.getHumidity().equals(new BigDecimal(35).setScale(2, BigDecimal.ROUND_HALF_UP)));
	}
}
